/**
 * @fileName schema.js
 * @description 后台管理页面的Schema集合
 * @author zhicheng.chai
 * @createTime 2021-08-15
 */

const mongoose = require('mongoose')
const Schema = mongoose.Schema
const moment = require('moment')

// Schema && Models
// 1. 分类Model
const categorySchema = new Schema({
    categoryName: {
        unique: true,
        required: true,
        type: String
    },
    children: {
        type: Array,
        default: []
    },
    createTime: {
        type: String
    },
    lastModifyTime: {
        type: String
    },
    parentId: {
        type: mongoose.Schema.Types.ObjectId
    }
})
const categoryModel = mongoose.model('Categories', categorySchema)

// 2. 物品Model
const itemSchema = new Schema({
    itemName: {
        type: String,
        required: true,
        unique: true
    },
    // 物品的图片信息，存一个URL放在图床中。
    picURL: {
        type: String,
        required: true
    },
    createTime: {
        type: String,
    },
    lastModifyTime: {
        type: String,
    },
})
const itemModel = mongoose.model("Items", itemSchema)

module.exports = {
    categoryModel,
    itemModel
}